import { secret } from '../../../utils/secret'

export const CHANGE_LOGIN = 'CHANGE_LOGIN'

const changeLoginAction = isLogin => ({
  type: CHANGE_LOGIN,
  isLogin
})

export const login = () => {
  return (dispatch, getState, axiosInstance) => {
    axiosInstance.get('/api/login.json').then(res => {
      dispatch(changeLoginAction(true))
    })
  }
}

export const logout = () => {
  return (dispatch, getState, axiosInstance) => {
    axiosInstance.get('/api/logout.json').then(res => {
      dispatch(changeLoginAction(false))
    })
  }
}

export const getLogin = () => {
  return (dispatch, getState, axiosInstance) => {
    return axiosInstance.get('/api/islogin.json').then(res => {
      const isLogin = res.data.data.login
      dispatch(changeLoginAction(isLogin))
    })
  }
}
